/**
 * @param {number[]} g
 * @param {number[]} s
 * @return {number}
 */
var findContentChildren = function(g, s) {
  g = g.sort((a, b) => a - b);
  s = s.sort((a, b) => a - b);
  let count = 0, jIndex = 0;
  for(let i = 0; i < g.length; i++) {
    while(jIndex < s.length && s[jIndex] < g[i]) {
      jIndex++;
    }
    if(jIndex >= s.length) {
      break;
    } else {
      jIndex++;
      count++;
    }
  }
  return count;
};
let g = [1,2,3], s = [1,1];
console.log(findContentChildren(g, s));
g = [1,2], s = [1,2,3];
console.log(findContentChildren(g, s));
g = [1,2,3], s = [3];
console.log(findContentChildren(g, s));
g = [10,9,8,7], s = [5,6,7,8];
console.log(findContentChildren(g, s));
